 <?php
 require_once('config.php');
 /**
 * @version		$Id: html.php 2011.08.20 thierry $
 * @package		site.models
 * @subpackage	com_projid
 * @copyright	Copyright (C) 2011 Pojid All rights reserved.
 * @license		GNU General Public License version 2 or later; see LICENSE.txt
 */
//issue du javabridge
if (!(get_cfg_var('java.web_inf_dir'))) {
	define ("JAVA_HOSTS", $JAVA_HOSTS);
	define ("JAVA_SERVLET", $JAVA_SERVLET);
	}
	
$pth = "http://" . $_SERVER["HTTP_HOST"] . $_SERVER["PHP_SELF"];
$path_parts = pathinfo($pth);

//A CHANGER POUR UN CHEMIN AUTO GENERE
//$imageURLPrefix ="http://localhost:8080/JavaBridge/sessionChartImages/";
//$imageURLPrefix ="http://192.168.111.130/sessionChartImages/";

require_once("$tomcatpath");

if(session_id() == "")
     session_start();


$ctx = java_context()->getServletContext();
$birtReportEngine = java("org.eclipse.birt.php.birtengine.BirtEngine")->getBirtEngine($ctx);
java_context()->onShutdown(java("org.eclipse.birt.php.birtengine.BirtEngine")->getShutdownHook());

try{
$report = $birtReportEngine->openReportDesign($myreport);
$task = $birtReportEngine->createRunAndRenderTask($report);

//Defini les paramètres à envoyer au BIRT UNIQUEMENT S'il y en a
if (isset($mybirt->result[0]->requete_id) AND $mybirt->result[0]->requete_id!="")
{$mybirt->setParameter($task);}


$taskOptions = new java("org.eclipse.birt.report.engine.api.HTMLRenderOption");
$outputStream = new java("java.io.ByteArrayOutputStream");
$taskOptions->setOutputStream($outputStream);
$taskOptions->setOutputFormat("html");
$ih = new java( "org.eclipse.birt.report.engine.api.HTMLServerImageHandler");
$taskOptions->setImageHandler($ih);
$taskOptions->setEnableAgentStyleEngine(true);
$taskOptions->setBaseImageURL("media/com_projid/reports/".session_id());
$taskOptions->setImageDirectory(JPATH_BASE."/media/com_projid/reports/".session_id());

$task->setRenderOption( $taskOptions );
$task->run();
$task->close();

} catch (JavaException $e) {
        echo $e; //"Error Calling BIRT";
}
echo $outputStream;
?>
